package com.gs.api.util.video.parse.huoshan;

import com.alibaba.fastjson.JSONObject;
import com.gs.api.util.video.parse.ParseConstant;
import com.gs.api.util.video.parse.ParseUtil;
import com.gs.api.util.video.parse.vo.VideoVo;
import org.jsoup.Jsoup;

/**
 * @author guoyunfei on 2022/4/14 16:08
 * @className HuoshanApp
 * @description TODO 火山app
 * @Version 1.0
 */
public class HuoshanApp {

    /**
     * 抖音火山视频
     *
     * @param url
     */
    public static VideoVo huoShanParseUrl(String url) {

        VideoVo videoVo = new VideoVo();

        try {
            // 获取短视频ID
            String itemId = ParseUtil.resp(url).split("item_id=")[1].split("&")[0];

            /**
             * （固定）https://share.huoshan.com/api/item/info?item_id=
             *  videoUrl = 视频链接 + 视频ID
             */
            String jsonStr = Jsoup.connect(ParseConstant.huoShanParseUrl + itemId).ignoreContentType(true).execute().body();

            JSONObject obj = JSONObject.parseObject(jsonStr);

            // 获取当前的视频的真实url
            String video_url = obj.getJSONObject("data").getJSONObject("item_info").getString("url");
            String cover = obj.getJSONObject("data").getJSONObject("item_info").getString("cover");

            videoVo.setVideoSrc(video_url);
            videoVo.setCoverSrc(cover);
            videoVo.setType(ParseConstant.PARSE_VIDEO);
            videoVo.setCopywriting(url);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return videoVo;
    }

}
